package com.meilele.controller.guoziyang;

import com.meilele.biz.guoziyang.SecDetailBusiness;
import com.meilele.biz.guoziyang.SecShowImageBusiness;
import com.meilele.biz.guoziyang.SeclaberBusiness;
import com.meilele.entity.guoziyang.SecDetail;
import com.meilele.entity.guoziyang.Seclaber;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/seclable")
public class SeclableController {

    @Resource
    private SeclaberBusiness seclaberBusiness;
    @Resource
    private SecDetailBusiness secDetailBusiness;
    @Resource
    private SecShowImageBusiness secShowImageBusiness;

/*
    装修效果图的基本展示页面
     */

    @RequestMapping("/list")
    public String findAll(Model model) {
        List<Seclaber> seclaberList = seclaberBusiness.findAll();
        model.addAttribute("lable", seclaberList);
        List<SecDetail> secDetailList = secDetailBusiness.findAll();
        model.addAttribute("detailList", secDetailList);
        return "second/second";
    }

    /*
    最新发布
     */
    @RequestMapping("/find1New")
    public String findByname(Model model) {
        List<Seclaber> seclaberList = seclaberBusiness.findAll();
        model.addAttribute("lable", seclaberList);
        List<SecDetail> secDetailList = secDetailBusiness.findNew();
        model.addAttribute("detailList", secDetailList);
        return "second/second";

    }

    /*
    设计师推荐排序
     */
    @RequestMapping("/findOld")
    public String findByOld(Model model) {
        List<Seclaber> seclaberList = seclaberBusiness.findAll();
        model.addAttribute("lable", seclaberList);
        List<SecDetail> secDetailList = secDetailBusiness.findOld();
        model.addAttribute("detailList", secDetailList);
        return "second/second";
    }

    @RequestMapping("/findPage")
    public String findPage(Model model) {
        List<Seclaber> seclaberList = seclaberBusiness.findAll();
        model.addAttribute("lable", seclaberList);
        return "second/demo_page4";
    }

    /*
    通过大类型的id去查询小类型的种类
    页面ajax调用方法
     */
    @ResponseBody
    @RequestMapping("/findById")
    public List<Seclaber> findById(Model model, Integer secLaberId) {
        List<Seclaber> seclaberList = seclaberBusiness.findById(secLaberId);
        return seclaberList;
    }





}













//       try {
//               String randName = UUID.randomUUID().toString();
//               File file1 = new File(Constants.IMAGE_PATH+randName);
//               if (!file1.exists()){
//                   detail.setStyleAlias(randName);
//                   detail.setStyleImage(files[0].getOriginalFilename());
//                   detail.setStyleDesigner(detail.getStyleCompany());
//                   files[0].transferTo(file1);
//               }
//
//       }catch (Exception e) {
//
//      }
//      int detailId = secDetailBusiness.saveDetail(detail);
//       int styId = detail.getStyleId();
//       for (int i =0 ;i < files.length ; i++ ) {
//           SecShow secShow = new SecShow();
//           secShow.setImageDetail(styId);
//           secShow.setShowImage();
//       }
//        for (int i = 0;i<laber.length;i++){
//
//            int laberId = laber[i];
//            int ww = secDetailBusiness.saveDeLa(laberId,styId);
//            System.out.println(ww+"--------ww");
//
//        }
//
//       }


